/* 
 * oms，一个基于J2EE架构运营支撑平台
 * Copyright © GrayRabbit Co., Ltd. All rights reserved.
 * Department:运营department
 * 更多信息请访问：
 * http://code.google.com/p/gray-rabbit-cms/
 */
package org.grayrabbit.cms.service.system.impl;

import java.util.List;

import org.grayrabbit.cms.dao.system.PluginVersionDao;
import org.grayrabbit.cms.entity.OperLog;
import org.grayrabbit.cms.entity.PluginVersion;
import org.grayrabbit.cms.service.system.PluginVersionService;
import org.grayrabbit.cms.vo.system.PluginVersionBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.grayrabbit.dao.util.Page;
import org.grayrabbit.service.impl.GenericServiceImpl;
/**
 * <b>OperLog</b>的service实现类，事务加此处：

 * @version 1.0,创建时间: 2012-01-06 13:30:59  
 */
@Service
@Transactional
public class PluginVersionServiceImpl extends GenericServiceImpl implements PluginVersionService {
	/**
	 * 注入dao层：
	 */
	@Autowired
	@Qualifier("pluginVersionDaoImpl")
	private PluginVersionDao pluginVersionDao;
	
	/**
	 * 此方法执行时为只读事务：
	 * @see PluginVersionService#getOperLog(String)
	 */
	@Transactional(readOnly=true)
	public PluginVersion getPluginVersion(final String versionId){
		PluginVersion pluginVersion = pluginVersionDao.findById(versionId);
		pluginVersionDao.initialize(pluginVersion);
		return pluginVersion;
	}
	
	/**
	 * @see PluginVersionService#delete(String)
	 */
	@Transactional
	public void delete(final PluginVersion pluginVersion) {
		pluginVersionDao.makeTransient(pluginVersion);
	}
	
	/**
	 * @see PluginVersionService#save(OperLog)
	 */
	@Transactional
	public void save(final PluginVersion pluginVersion) {
		pluginVersionDao.makePersistent(pluginVersion);		
	}
	
	@Transactional(readOnly=true)
	public List<PluginVersion> getAll(){
		return pluginVersionDao.findAll();
	}
	/**
	 * 此方法执行时为只读事务：
	 * @see PluginVersionService#getPage(PluginVersionBean)
	 */
	@Transactional(readOnly=true)
	public Page<PluginVersion> getPage(final PluginVersionBean pluginVersionBean){
		Page<PluginVersion> page =  new Page<PluginVersion>();
		page.setTotal(pluginVersionDao.count(pluginVersionBean));
		page.setResult(pluginVersionDao.findByQc(pluginVersionDao.assembly(pluginVersionBean)));
		return page;
	}

	/**
	 * 此方法执行时为只读事务：
	 * @see PluginVersionService#list(Page, PluginVersionBean)
	 */
	public void list(Page<PluginVersion> page, PluginVersionBean pluginVersionBean) {
		if(page==null)
			return;
		if(page.isAutoCount()){
			page.setTotal(pluginVersionDao.count(pluginVersionBean));
		}
		page.setResult(pluginVersionDao.findByPage(page,pluginVersionBean));
	}
	
	/**
	 * 根据主键id列删除，批量删除OperLog
	 * @see PluginVersionService#delete(String[])
	 */
	public void delete(final String[] key) {
		int i =0;
		for(String id : key){
			pluginVersionDao.makeTransient(pluginVersionDao.findById(id));
			i++;
			if(i==MAX_CLEAR)
				pluginVersionDao.clear();
		}
		
	}
 
}